package org.zcj.util;

import java.util.HashMap;
import java.util.Map;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;

public class MessageUtil {
	private static final String appKey = "b328590c90cfbdc47f18807d";
	private static final String masterSecret = "89580cd31aadd89db948b7d0";
	private static final int timeToLive = 60 * 60 * 24;

	private static JPushClient jpush = null;
	private static PushResult result;

	public static int sendMessage(String title, String content, String userID) {
		int code = 0;
		jpush = new JPushClient(masterSecret, appKey, timeToLive);
		Map<String, String> extras = new HashMap<String, String>();
		extras.put("channel", "channel");
		try {
			System.out.println(title + "------------" + content + "----------"
					+ userID);
			result = jpush.sendAndroidNotificationWithAlias(title, content,
					extras, userID);
			if (result.isResultOK()) {
				System.out.println(result.getOriginalContent());

			} else {
				code = -1;
			}
		} catch (APIConnectionException e) {
			code = -1;
			e.printStackTrace();
		} catch (APIRequestException e) {
			code = -1;
			e.printStackTrace();
		}
		return code;
	}

}
